[KEXEC] Clean up kexec code and fix panic-induced reboot when
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 14 Dec 2006 15:06:22 +0000 (15:06 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Thu, 14 Dec 2006 15:06:22 +0000 (15:06 +0000)
kdump is not in use.
Signed-off-by: Keir Fraser <keir@xensource.com>
xen/arch/x86/crash.c
xen/arch/x86/traps.c
xen/common/kexec.c
xen/drivers/char/console.c
xen/include/xen/kexec.h

index 933846d1cdeb0387e938e32e7ab79922923414db..a754cbbaab07fdbc07f6f74ff3e39e6bc610c923 100644 (file)
@@ -28,6 +28,7 @@
 #include <asm/hvm/hvm.h>
 
 static atomic_t waiting_for_crash_ipi;
+static unsigned int crashing_cpu;
 
 static int crash_nmi_callback(struct cpu_user_regs *regs, int cpu)
 {
@@ -39,7 +40,7 @@ static int crash_nmi_callback(struct cpu_user_regs *regs, int cpu)
         return 1;
     local_irq_disable();
 
-    machine_crash_save_cpu();
+    kexec_crash_save_cpu();
     disable_local_APIC();
     atomic_dec(&waiting_for_crash_ipi);
     hvm_disable();
@@ -67,6 +68,8 @@ static void nmi_shootdown_cpus(void)
 {
     unsigned long msecs;
 
+    crashing_cpu = smp_processor_id();
+
     atomic_set(&waiting_for_crash_ipi, num_online_cpus() - 1);
     /* Would it be better to replace the trap vector here? */
     set_nmi_callback(crash_nmi_callback);
@@ -86,18 +89,10 @@ static void nmi_shootdown_cpus(void)
     disable_local_APIC();
 }
 
-static void crash_save_xen_notes(void)
+void machine_crash_shutdown(void)
 {
     crash_xen_info_t *info;
 
-    info = machine_crash_save_info();
-
-    info->dom0_pfn_to_mfn_frame_list_list = \
-        dom0->shared_info->arch.pfn_to_mfn_frame_list_list;
-}
-
-void machine_crash_shutdown(void)
-{
     local_irq_disable();
 
     nmi_shootdown_cpus();
@@ -106,7 +101,9 @@ void machine_crash_shutdown(void)
 
     hvm_disable();
 
-    crash_save_xen_notes();
+    info = kexec_crash_save_info();
+    info->dom0_pfn_to_mfn_frame_list_list =
+        dom0->shared_info->arch.pfn_to_mfn_frame_list_list;
 }
 
 /*
index 11960e56fb79341449587bb617e346b283793b6b..7d9b00dfad4ae83bd2b35b4daa0f9a4c05604359 100644 (file)
@@ -1665,7 +1665,7 @@ static void unknown_nmi_error(unsigned char reason)
         printk("Uhhuh. NMI received for unknown reason %02x.\n", reason);
         printk("Dazed and confused, but trying to continue\n");
         printk("Do you have a strange power saving mode enabled?\n");
-        machine_crash_kexec();
+        kexec_crash();
     }
 }
 
index 5906687a029ddfbe1f934ff261898da0c20c96dc..4fb9c6e706c90e72abf632ff886f36fd003d274e 100644 (file)
@@ -24,7 +24,6 @@
 
 DEFINE_PER_CPU (crash_note_t, crash_notes);
 cpumask_t crash_saved_cpus;
-int crashing_cpu;
 
 xen_kexec_image_t kexec_image[KEXEC_IMAGE_NR];
 
@@ -58,38 +57,34 @@ custom_param("crashkernel", parse_crashkernel);
 
 static void one_cpu_only(void)
 {
-   /* Only allow the first cpu to continue - force other cpus to spin */
+    /* Only allow the first cpu to continue - force other cpus to spin */
     if ( test_and_set_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags) )
-    {
-        while (1);
-    }
+        for ( ; ; ) ;
 }
 
-/* Save the registers in the per-cpu crash note buffer */
-
-void machine_crash_save_cpu(void)
+/* Save the registers in the per-cpu crash note buffer. */
+void kexec_crash_save_cpu(void)
 {
     int cpu = smp_processor_id();
     crash_note_t *cntp;
 
-    if ( !cpu_test_and_set(cpu, crash_saved_cpus) )
-    {
-        cntp = &per_cpu(crash_notes, cpu);
-        elf_core_save_regs(&cntp->core.desc.desc.pr_reg,
-                           &cntp->xen_regs.desc.desc);
+    if ( cpu_test_and_set(cpu, crash_saved_cpus) )
+        return;
 
-        /* setup crash "CORE" note */
-        setup_crash_note(cntp, core, CORE_STR, CORE_STR_LEN, NT_PRSTATUS);
+    cntp = &per_cpu(crash_notes, cpu);
+    elf_core_save_regs(&cntp->core.desc.desc.pr_reg,
+                       &cntp->xen_regs.desc.desc);
 
-        /* setup crash note "Xen", XEN_ELFNOTE_CRASH_REGS */
-        setup_crash_note(cntp, xen_regs, XEN_STR, XEN_STR_LEN,
-                         XEN_ELFNOTE_CRASH_REGS);
-    }
-}
+    /* Set up crash "CORE" note. */
+    setup_crash_note(cntp, core, CORE_STR, CORE_STR_LEN, NT_PRSTATUS);
 
-/* Setup the single Xen specific info crash note */
+    /* Set up crash note "Xen", XEN_ELFNOTE_CRASH_REGS. */
+    setup_crash_note(cntp, xen_regs, XEN_STR, XEN_STR_LEN,
+                     XEN_ELFNOTE_CRASH_REGS);
+}
 
-crash_xen_info_t *machine_crash_save_info(void)
+/* Set up the single Xen-specific-info crash note. */
+crash_xen_info_t *kexec_crash_save_info(void)
 {
     int cpu = smp_processor_id();
     crash_note_t *cntp;
@@ -99,7 +94,7 @@ crash_xen_info_t *machine_crash_save_info(void)
 
     cntp = &per_cpu(crash_notes, cpu);
 
-    /* setup crash note "Xen", XEN_ELFNOTE_CRASH_INFO */
+    /* Set up crash note "Xen", XEN_ELFNOTE_CRASH_INFO. */
     setup_crash_note(cntp, xen_info, XEN_STR, XEN_STR_LEN,
                      XEN_ELFNOTE_CRASH_INFO);
 
@@ -117,45 +112,34 @@ crash_xen_info_t *machine_crash_save_info(void)
     return info;
 }
 
-void machine_crash_kexec(void)
+void kexec_crash(void)
 {
     int pos;
-    xen_kexec_image_t *image;
-
-    one_cpu_only();
 
-    machine_crash_save_cpu();
-    crashing_cpu = smp_processor_id();
+    pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
+    if ( !test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
+        return;
 
+    one_cpu_only();
+    kexec_crash_save_cpu();
     machine_crash_shutdown();
 
-    pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
+    machine_kexec(&kexec_image[KEXEC_IMAGE_CRASH_BASE + pos]);
 
-    if ( test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
-    {
-        image = &kexec_image[KEXEC_IMAGE_CRASH_BASE + pos];
-        machine_kexec(image); /* Does not return */
-    }
+    BUG();
 }
 
 static void do_crashdump_trigger(unsigned char key)
 {
-    int pos = (test_bit(KEXEC_FLAG_CRASH_POS, &kexec_flags) != 0);
-    if ( test_bit(KEXEC_IMAGE_CRASH_BASE + pos, &kexec_flags) )
-    {
-        printk("'%c' pressed -> triggering crashdump\n", key);
-        machine_crash_kexec();
-    }
-    else
-    {
-        printk("'%c' pressed -> no crash kernel loaded -- not triggering crashdump\n", key);
-    }
+    printk("'%c' pressed -> triggering crashdump\n", key);
+    kexec_crash();
+    printk(" * no crash kernel loaded!\n");
 }
 
 static __init int register_crashdump_trigger(void)
 {
-       register_keyhandler('C', do_crashdump_trigger, "trigger a crashdump");
-       return 0;
+    register_keyhandler('C', do_crashdump_trigger, "trigger a crashdump");
+    return 0;
 }
 __initcall(register_crashdump_trigger);
 
@@ -303,7 +287,7 @@ static int kexec_exec(XEN_GUEST_HANDLE(void) uarg)
         machine_reboot_kexec(image); /* Does not return */
         break;
     case KEXEC_TYPE_CRASH:
-        machine_crash_kexec(); /* Does not return */
+        kexec_crash(); /* Does not return */
         break;
     }
 
index 1bca60cc8036a7df0770b15a211cc7c6ccf1f52e..457ab393aa30972b22f9dbb62642ac6d79c6dbd4 100644 (file)
@@ -866,7 +866,7 @@ void panic(const char *fmt, ...)
 
     debugger_trap_immediate();
 
-    machine_crash_kexec();
+    kexec_crash();
 
     if ( opt_noreboot )
     {
index c22bfc8f5ed95a714947f61960fbdf688de6aa95..be09c0a1ab988db4ed9aea557c01fa721cebb065 100644 (file)
@@ -5,8 +5,6 @@
 #include <asm/percpu.h>
 #include <xen/elfcore.h>
 
-extern int crashing_cpu;
-
 typedef struct xen_kexec_reserve {
     unsigned long size;
     unsigned long start;
@@ -27,9 +25,9 @@ int machine_kexec_load(int type, int slot, xen_kexec_image_t *image);
 void machine_kexec_unload(int type, int slot, xen_kexec_image_t *image);
 void machine_kexec_reserved(xen_kexec_reserve_t *reservation);
 void machine_reboot_kexec(xen_kexec_image_t *image);
-void machine_crash_kexec(void);
-void machine_crash_save_cpu(void);
-crash_xen_info_t *machine_crash_save_info(void);
+void kexec_crash(void);
+void kexec_crash_save_cpu(void);
+crash_xen_info_t *kexec_crash_save_info(void);
 void machine_crash_shutdown(void);
 
 #endif /* __XEN_KEXEC_H__ */